package com.zz.xapp.provider

import android.app.Application
import android.content.Context
import android.view.Gravity
import com.zz.framework.core.utils.XPreference
import com.zz.framework.core.Kernel
import com.zz.framework.core.utils.Density
import com.zz.toast.ActivityToast
import com.zz.toast.ToastStrategy
import com.zz.toast.ToastUtils
import com.zz.toast.config.IToast
import com.zz.xapp.config.AppBaseUIFactory
import com.zz.xapp.config.AppRetrofitConfig


/**
 * @version: V1.0
 * 默认初始化  并提供 全局 applicationContext
 */
object InitializationContextProvider {
    lateinit var application: Application
    fun attachContext(context: Context?) {
        application = context as? Application ?: throw RuntimeException("init error !")
        Kernel.initRetrofitConfig(AppRetrofitConfig())
        Kernel.initBaseUIFactory(AppBaseUIFactory::class.java)
        XPreference.init(application)
        Density.setDensity(application,375f,812f)
        ToastUtils.init(application, object : ToastStrategy() {
            override fun createToast(application: Application): IToast {
                val toast = super.createToast(application)
                if (toast is ActivityToast) {
                    val activityToast = toast as ActivityToast
                    // 设置短 Toast 的显示时长（默认是 2000 毫秒）
                    activityToast.shortDuration = 1000
                    // 设置长 Toast 的显示时长（默认是 3500 毫秒）
                    activityToast.longDuration = 5000
                    activityToast.setGravity(Gravity.TOP,0,200)
                }
                return toast
            }
        })
    }



}